package com.medical.guide.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.medical.domain.Disease;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;

import com.medical.guide.service.IDiseaseService;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.core.domain.Result;
import com.medical.common.core.utils.poi.ExcelUtil;
import com.medical.common.core.domain.Result;import com.medical.common.core.domain.Result;
import com.medical.common.core.web.page.TableDataInfo;

/**
 * 常见病Controller
 * 
 * @author medical
 * @date 2024-07-19
 */
@RestController
@RequestMapping("/disease")
public class DiseaseController extends BaseController
{
    @Autowired
    private IDiseaseService diseaseService;

    /**
     * 查询常见病列表
     */
    @RequiresPermissions("guide:disease:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(Disease disease)
    {
        startPage();
        List<Disease> list = diseaseService.selectDiseaseList(disease);
        return getDataTable(list);
    }

    /**
     * 导出常见病列表
     */
    @RequiresPermissions("guide:disease:export")
    @Log(title = "常见病", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Disease disease)
    {
        List<Disease> list = diseaseService.selectDiseaseList(disease);
        ExcelUtil<Disease> util = new ExcelUtil<Disease>(Disease.class);
        util.exportExcel(response, list, "常见病数据");
    }

    /**
     * 获取常见病详细信息
     */
    @RequiresPermissions("guide:disease:query")
    @GetMapping(value = "/{diseaseId}")
    public Result getInfo(@PathVariable("diseaseId") Long diseaseId)
    {
        return success(diseaseService.selectDiseaseByDiseaseId(diseaseId));
    }

    /**
     * 新增常见病
     */
    @RequiresPermissions("guide:disease:add")
    @Log(title = "常见病", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody Disease disease)
    {
        return toAjax(diseaseService.insertDisease(disease));
    }

    /**
     * 修改常见病
     */
    @RequiresPermissions("guide:disease:edit")
    @Log(title = "常见病", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody Disease disease)
    {
        return toAjax(diseaseService.updateDisease(disease));
    }

    /**
     * 删除常见病
     */
    @RequiresPermissions("guide:disease:remove")
    @Log(title = "常见病", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diseaseIds}")
    public Result remove(@PathVariable Long[] diseaseIds)
    {
        return toAjax(diseaseService.deleteDiseaseByDiseaseIds(diseaseIds));
    }

    /**
     * 根据位置查询常见病
     * @param positionId
     * @return
     */
    @GetMapping("/selectPositionIdList/{positionId}")
    public Result<TableDataInfo> selectPositionIdList(@PathVariable("positionId") Long positionId) {
        List<Disease> diseases = diseaseService.selectPositionIdList(positionId);
        return getDataTable(diseases);
    }

    /**
     * 根据位置查询常见病
     */
    @GetMapping("/spark")
    public void spark() {
        Spark spark = new Spark();
        try {
            String authorization = spark.getAuthorization();
            System.out.println(authorization);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

}
